import { fetchList, delObj } from "@/views/client-manage/api/clientprovider";
import clientExport from "@/views/client-manage/components/client-export.vue";
import pager from "@/assets/vue-mixin/pager";
import { mapState } from "vuex";
export default {
    name: "client-provider",
    mixins: [pager],
    components: {
        clientExport
    },
    mounted() {
        //获取数据字段的值
        this.totalSearchData[0].children = this.provider_type;
        console.log(this.provider_type, "ff");
    },
    computed: mapState({
        //客户类型
        provider_type: state => {
            let data =
                state.dict.find(item => item.type === "provider_type") || {};
            //let list = data.children || []
            return data.children || [];
        }
    }),

    data() {
        return {
            tableData: [],
            searchForm: {},

            totalSearchData: [
                {
                    label: "客户类型",
                    value: "type",
                    type: "select",
                    model: "type",
                    children: []
                }
            ],
            searchDataFrom: {},
            timeData: [],
            placeholder: "请输入客户名称"
        };
    },

    methods: {
        getListData() {
            fetchList(Object.assign({}, this.pageParams, this.searchForm))
                .then(response => {
                    this.setListData(response.data);
                })
                .catch(() => {
                    console.log("catch");
                });
        },
        searchByKey(val) {
            if (val) {
                this.searchForm.clientProviderName = val;
            } else {
                delete this.searchForm.clientProviderName;
            }
            if (this.searchDataFrom.type) {
                let sum = [];
                this.searchDataFrom.types.map(item => {
                    sum.push(item.value);
                });
                this.searchForm.clientProviderTypes = sum;
            }
            this.resetList();
        },
        //qh+：点击编辑跳转到新的页面
        toEdit(row) {
            this.$router.push({
                path: "/client-manage/provider-manage/edit?id=" + row.supplierId
            });
        },
        //qh+:点击查看跳转到查看页面
        toAdd() {
            this.$router.push({ path: "/client-manage/provider-manage/add" });
        },
        toImport() {
            this.$router.push({
                path:
                    "/client-manage/provider-manage/import?clientType=provider"
            });
        },
        //qh+:点击名称跳转
        toPerson(row) {
            //点击列表页名称跳转
            this.$router.push({
                path: "/client-manage/provider-manage/look?id=" + row.supplierId
            });
        },
        //qh+:显示导出弹出框
        toExport() {
            this.$refs.clientExport.show("provider");
        },
        typeFormat(row, column) {
            if (row.clientProviderType == 0) {
                return this.provider_type[0].label;
            } else if (row.clientProviderType == 1) {
                return this.provider_type[1].label;
            } else if (row.clientProviderType == 2) {
                return this.provider_type[2].label;
            } else if (row.clientProviderType == 3) {
                return this.provider_type[3].label;
            } else if (row.clientProviderType == 4) {
                return this.provider_type[4].label;
            }
        },
        //qh+：重置
        searchReset() {
            // console.log("====searchReset")
            //清空选中的数据
            this.searchForm = {};
            //重新查询
            this.resetList();
        },
        exportTable() {
            this.publicExport(
                "报销记录",
                "/api/clientlessee/clientlessee_recording_download",
                this.searchForm
            );
        },
        rowDel(row) {
            //取出数据，由于字段名不一样，需要创建一个对应实体类表字段名的对象作为参数
            //也可以直接obj=row
            var obj = {};
            //obj.clientLesseeId=row.clientLesseeId;
            this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    console.log(row);

                    //删除
                    delObj(row.supplierId).then(response => {
                        this.resetList();
                    });

                    this.$message({
                        type: "success",
                        message: "删除成功!"
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
        }
    }
};
